import simplejson
from lyricemo.utils import get_emodict,get_c2wlist,split_by_emoword
from commonprocess.read_ano import read_mid_p

emo_dict = get_emodict()
c2wlist = get_c2wlist()

def run():
    mid2p = read_mid_p()
    bad_mid_list = simplejson.load(open('/Users/wangxing/Mycode/webscrach/nlptoylocal/bad_audio_lyric_mid.json'))

    outf = open('but_line_words.html','w')
    lines = open('but_line_list.txt').readlines()
    # only show the error ones..
    # should change the out put of but_line_list
    for line in lines:
        line = line.decode('utf-8')
        ws = line.split(':')
        mid = int(ws[0])
        line = ws[1]

        # show the split_line_results
        w_info_list = split_by_emoword(line,emo_dict,c2wlist)
        tmp_str = ""
        pos_word = 0
        neg_word = 0
        for w_info in w_info_list:
            if w_info.has_key('emo'):
                if w_info['emo'] > 0:
                    tmp_str += "<span style='color:#ff0000'>%s</span>"%w_info['w']
                    pos_word = 1
                else:
                    tmp_str += "<span style='color:#00ffff'>%s</span>"%w_info['w']
                    neg_word = 1
            else:
                tmp_str += w_info['w']
        if mid in bad_mid_list:
            continue
            print>>outf,"<span style='color:#ff0000'>bad song</span>"

        # remove that have conflict audio and lyric
        if mid2p[mid] < 5 and pos_word == 1:
            print>>outf,mid,mid2p[mid],tmp_str.encode('utf-8')+"<br/>"
        if mid2p[mid] > 5 and neg_word == 1:
            print>>outf,mid,mid2p[mid],tmp_str.encode('utf-8')+"<br/>"

    outf.close()

if __name__ == "__main__":
    run()
